﻿@{
    ViewBag.Title = "KeepForm";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}
<script>
    var keyValue = request('keyValue');
    var ContractId = "";
    var CBBkeyValue = "";
    var uid;
    $(function () {
        InitControl();
    })


    //初始化数据
    function InitControl() {
        //组织机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "===选择组织机构===",
            click: function (item) {
            }
        });
        if (!!keyValue) {
            $.SetForm({
                url: "../../QualificationManage/RentContract/GetInfo",
                param: { keyValue: keyValue },
                success: function (data) {
                    
                    ContractId = data.ContractDWelling.Id;

                    var State = "待审批";
                    if ((data.CBBInfo != "" && data.CBBInfo != null && data.CBBInfo != "null") && data.CBBInfo.Type == 2) {
                        $("#CBB").SetWebControls(data.CBBInfo);
                        $("#Info1").SetWebControls(data.CBBInfo);
                        uid = data.CBBInfo.CreateUserId;
                        CBBkeyValue = data.CBBInfo.Id;
                        $("#RentYearDate1").val(GetTimes(data.ContractDWelling.EndDate, data.CBBInfo.EndRenewDate));
                        if (data.CBBInfo.State == 1) {
                            State = "审批中";
                            $("#btn_Save").attr("disabled", "disabled");
                            $("#btn_Submit").attr("disabled", "disabled");
                            $(".BaseClass").attr("disabled", "disabled");
                        }
                        if (data.CBBInfo.State == 2) {
                            State = "审批通过";
                            $("#btn_Save").attr("disabled", "disabled");
                            $("#btn_Submit").attr("disabled", "disabled");
                            $(".BaseClass").attr("disabled", "disabled");
                        }
                        if (data.CBBInfo.State == 3) {
                            State = "审批未通过";
                            $("#btn_Save").attr("disabled", "disabled");
                            $("#btn_Submit").attr("disabled", "disabled");
                            $(".BaseClass").attr("disabled", "disabled");
                        }
                    }
                    else {
                        $("#btn_Submit").attr("disabled", "disabled");
                    }
                    $("#State").text(State);
                    $("#Info").SetWebControls(data.ContractDWelling);
                    $("#Info").SetWebControls(data.MemberInfo);
                    $("#Info").SetWebControls(data.PStruct);
                    $("#Info").SetWebControls(data.Room);
                    $("#RoomCode").val(data.PStruct.Code);
                    $("#MonthlyRent").val(data.PStructInfo.MonthlyRent);
                    $("#RCode").val(data.ContractDWelling.Code);
                    if (data.ContractDWelling.BeginDate != "" && data.ContractDWelling.EndDate != "") {
                        $("#RentYearDate").val(GetTimes(data.ContractDWelling.BeginDate, data.ContractDWelling.EndDate));
                    }
                }
            })
        }
    }

    //获取数据
    function GetTimes(sdate, edate) {
        
        var Sdate = Date.parse(sdate);
        var Edate = Date.parse(edate);
        var a = Math.floor((Edate - Sdate) / 86400000);
        var y = Math.floor(a / 365);
        var m = Math.floor((a - y * 365) / 30);
        var d = (a - y * 365 - m * 30);
        var RentYearDate = "";
        RentYearDate = y + "年" + m + "个月" + d + "天";
        $("#RenewYear").val(a);
        return RentYearDate;
    }
    //计算时间戳
    function GetDateTimes() {

        var BeginDate = $("#EndDate").val();
        var EndDate = $("#EndRenewDate").val();
        if (EndDate < BeginDate) {
            //dialogMsg("租赁结束时间必须大于之前合同的结束时间。", 0);
            return false;
        }
        if (BeginDate != "" && EndDate != "") {
            $("#RentYearDate1").val(GetTimes(BeginDate, EndDate));

        }
    }
    function btn_Save(type) {
        
        var keyValue = CBBkeyValue;
        var queryJson = {
            ContractId: ContractId,
            Code: $("#Code").val(),
            RenewYear: $("#RenewYear").val(),
            EndRenewDate: $("#EndRenewDate").val(),
            Description: $("#Description").val(),
            ReLeaseType: 0,
            CreateUserId: uid
        };
        if (type == 1) {
            $.SaveForm({
                url: "../../QualificationManage/RentContract/KeepRent?keyValue=" + keyValue + "&type=" + type + "&queryJson=" + JSON.stringify(queryJson),
                loading: "正在保存数据...",
                success: function () {

                }
            })
        }
        if (type == 2) {
            if (!$('#Info1').Validform()) {
                return false;
            }
            dialogConfirm('提交后将无法更改，是否提交？', function (r) {
                if (r) {
                    $.SaveForm({
                        url: "../../QualificationManage/RentContract/KeepRent?keyValue=" + keyValue + "&type=" + type + "&queryJson=" + JSON.stringify(queryJson),
                        loading: "正在保存数据...",
                        success: function () {
                        }
                    })
                }
            });
        }
    }
    function btn_Close() {
        dialogClose();
    }

</script>
<style>
    #Info, #Info td {
        border: 1px solid #ccc;
    }

    .cs-1 {
        background-color: #DDF0ED;
    }

    .cs-2 {
        border: none;
    }
</style>
<div>
    <table class="form" id="CBB" style="margin-top:20px; width:90%; margin-left:5%;">
        <tr>
            <td class="formTitle">单据状态:</td>
            <td class="formValue"><span id="State" style="color:red;font-size:20px;"></span></td>
            <td class="formTitle">申请单编号:</td>
            <td class="formValue"><input class="form-control" disabled placeholder="系统自动编号" id="Code" readonly type="text" /></td>
            <td class="formTitle">申请日期:</td>
            <td class="formValue"><input id="Date" type="text" class="form-control input-wdatepicker BaseClass " readonly placeholder="请输入申请日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd ' })" /></td>
        </tr>
    </table>

    <table class="form" id="Info" style="margin-top: 20px; width: 90%; margin-left: 5%;">
        <tr>
            <td class="formTitle cs-1">所属机构</td>
            <td class="formValue"><div id="OrganizeId" type="selectTree" readonly class="ui-select cs-2 "></div></td>
            <td class="formTitle cs-1">合同编号</td>
            <td class="formValue"><input class="form-control cs-2" id="RCode" readonly type="text" /></td>
            <td class="formTitle cs-1">签约日期</td>
            <td class="formValue"><input id="SignDate" type="text " class="form-control input-wdatepicker cs-2 " disabled placeholder="请输入申请日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd ' })" /></td>
        </tr>
        <tr>
            <td class="formTitle cs-1">租赁房屋</td>
            <td class="formValue" colspan="3"><input class="form-control cs-2" id="AllName" readonly type="text" /></td>
            <td class="formTitle cs-1">房屋编号</td>
            <td class="formValue"><input class="form-control cs-2" id="RoomCode" readonly type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs-1">建筑面积</td>
            <td class="formValue"><input class="form-control cs-2" id="Area" readonly type="text" /></td>
            <td class="formTitle cs-1">户型</td>
            <td class="formValue"><input class="form-control cs-2" id="HouseType" readonly type="text" /></td>
            <td class="formTitle cs-1">每月租金</td>
            <td class="formValue"><input class="form-control cs-2" id="MonthlyRent" readonly type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs-1">承租人</td>
            <td class="formValue"><input class="form-control cs-2" id="Name" readonly type="text" /></td>
            <td class="formTitle cs-1">身份证号</td>
            <td class="formValue"><input class="form-control cs-2" id="IDCard" readonly type="text" /></td>
            <td class="formTitle cs-1">联系电话</td>
            <td class="formValue"><input class="form-control cs-2" id="Phone" readonly type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs-1">所属单位</td>
            <td class="formValue"><input class="form-control cs-2" id="CompanyName" readonly type="text" /></td>
            <td class="formTitle cs-1">营业执照</td>
            <td class="formValue"><input class="form-control cs-2" id="" readonly type="text" /></td>
            <td class="formTitle cs-1">单位电话</td>
            <td class="formValue"><input class="form-control cs-2" id="CompanyPhone" readonly type="text" /></td>
        </tr>
        <tr>
            <td class="formTitle cs-1">租赁开始时间</td>
            <td class="formValue"><input id="BeginDate" type="text" readonly class="form-control input-wdatepicker cs-2 " readonly placeholder="请输入申请日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd ")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd ' })" /></td>
            <td class="formTitle cs-1">租赁结束时间</td>
            <td class="formValue"><input id="EndDate" type="text" readonly class="form-control input-wdatepicker cs-2 " readonly placeholder="请输入申请日期" value="@LeSoft.Util.Time.GetToday("yyyy-MM-dd ")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd ' })" /></td>
            <td class="formTitle cs-1">租赁年限</td>

            <td class="formValue">
                <input id="RentYear" class="form-control" type="hidden" />
                <input class="form-control cs-2" id="RentYearDate" readonly type="text" />
            </td>
        </tr>

    </table>
    <table class="form" id="Info1" style="margin-top: 20px; width: 90%; margin-left: 5%;">
        <tr>
            <td class="formTitle">续租年限</td>
            <td class="formValue">
                <input id="RenewYear" class="form-control" type="hidden" />
                <input id="RentYearDate1" readonly disabled class="form-control BaseClass" placeholder="选择终止日期后自动生成" type="text" isvalid="yes" checkexpession="NotNull" />
            <td class="formTitle">租赁终止日期</td>
            <td class="formValue"><input id="EndRenewDate" type="text" isvalid="yes" checkexpession="NotNull" class="form-control input-wdatepicker BaseClass " placeholder="请输入申请日期" onblur="GetDateTimes();" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd ', minDate: '#F{$dp.$D(\'EndDate\')}' }) " /></td>
        </tr>
        <tr>
            <td class="formTitle">附加说明</td>
            <td class="formValue" colspan="5"><textarea id="Description" class="form-control BaseClass" style="height: 80px;"></textarea></td>
        </tr>
        <tr style="text-align:center;"></tr>
    </table>
</div>
<div class="form-button" id="wizard-actions">
    <a id="btn_Save" class="btn btn-default" style="background-color: #5CB85C" onclick="btn_Save(1)">保存</a>
    <a id="btn_Submit" class="btn btn-default" style="background-color: #2C86CE" onclick="btn_Save(2)">提交申请</a>
    <a id="btn_Close" class="btn btn-default" style="background-color: #D9534F" onclick="btn_Close()">取消</a>
</div>
